	var thesum=0;    //待办事项返回数量
var resdata=[];  //待办事项返回数据
var username = sessionStorage.getItem("name"); 
$('#name').text(sessionStorage.getItem("name"));
var _config ;
var photoUrl = [];//拍照列表
var thecolor = 'red'//未回复 未完成的字体颜色 
var sendData = {};  //待办事项
sendData.userid = sessionStorage.getItem("userId");
$.ajax({              //待办事项
	url: "../../shop_open_info/getBody"
	,type:'post'
	,async: false
	,contentType: "application/json; charset=utf-8"
	,data:JSON.stringify(sendData) 
	,dataType:'json'
	,success: function(res){
		console.log(res);
		resdata = res.data
	},error : function(XMLHttpRequest, textStatus, errorThrown) {
			alert(XMLHttpRequest.status);
			alert(XMLHttpRequest.readyState);
			alert(textStatus);
	}
});
$(document).ready(function(){
	daiban();
});	
function daiban(){  
	var sno;
	var title=0;
	var shixiang = 0;
	var sum = 0;
	var thein='in';
	for(var i =0;i<resdata.length;i++){
		shixiang ++;
		if(sno==undefined || sno != resdata[i].sno){
				if(title !=0){
					console.log(title);
					$('#sum'+title).html(sum);
					sum=0;
				}
				title +=1;
				shixiang =1;
				if(title!=1){thein='';}
				$('#daibanid').append('<div class="panel panel-default">'
				+'<div class="panel-heading bg_white add_pos_re add_pad_tb20p bg_blue">'
				+'<h4 class="panel-title">'
				+'<a data-toggle="collapse" data-parent="#daibanid"  style="color:#fff;"href="#collapseOne'+title+'">'	
				+'<i class="iconfont">&#xe60b;</i>&nbsp;'+resdata[i].shopcode +'、'+resdata[i].shopname+' <div style="width:350px;margin-top:-17px">&nbsp;</div>'
				+'<div class="nb_box" id="sum'+title+'"></div>'
				+'</a>'	
				+'</h4>'
				+'</div>'
				+'<div id="collapseOne'+title+'" class="panel-collapse collapse '+thein+'">'
				+'<div class="col-xs-12" id="title'+title+'"></div>'
				+'</div>'
				+'</div>'	
			);
			sno =resdata[i].sno;
				$('#title'+title).append(
				//	'<h5>&nbsp;新店信息</h5>'
					'<h5>&nbsp;&nbsp;地址：'+resdata[i].address+'</h5>'
					+'<h5>&nbsp;&nbsp;开业日期：'+resdata[i].opentime+'</h5>'
					+'<h5>&nbsp;&nbsp;开业督导：'+resdata[i].openemployeename+'</h5>'
					+'<h5>&nbsp;&nbsp;联系电话：'+resdata[i].openemployeephone+'</h5>'
					+'<h5>&nbsp;&nbsp;业主：'+resdata[i].name+'</h5>'
					+'<h5>&nbsp;&nbsp;联系电话：'+resdata[i].phone+'</h5>'
				);
				if(resdata[i].shenheflag==4){
					$('#title'+title).append('<h5>&nbsp;&nbsp;终止原因：'+resdata[i].stopreason+'</h5>')
				}
				
			}
				$('#title'+title).append('<div class="widget-header widget-header-flat widget-header-small" style="border-top:10px #e5e5e5 solid;display:'+(resdata[i].shenheflag==4?'none':'')+'">'   //待办事项标题 e5e5e5 
					+'<h5 class="black" style="">'+'事项'+shixiang+'</h5>'
					+'<div class="widget-toolbar" id="shangpinmore">'
					+'</div>'
					+'</div>');		
					
				$('#title'+title).append(
						'<div class="col_box" style="display:'+(resdata[i].shenheflag==4?'none':'')+'">'  

						+'<div>'							
						+'<div class="widget-box">'			
						+'<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_bgrey">'
						+'<h5><i class="iconfont">&#xe600;</i>&nbsp;项目<span class="red"></span></h5>'		
						+'</div>'
						+'<div class="widget-body zhediebox1">'
						+'<div class="widget-main pd_div" style="padding:0;">'
						+'<div class="clearfix jy_div" style="padding:0;">'
						+'<textarea id="project'+i+'"  rows="" cols="" class="pull-left add_bor_none add_pad_tb10p" readonly="readonly" >'+resdata[i].project+'</textarea>'
						+'</div>'
						+'</div></div></div></div>'	
	
						+'<div class="widget-box">'			
						+'<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_bgrey ">'				
						+'<h5><i class="iconfont">&#xe609;</i>&nbsp;预计完成时间<span class="red"></span></h5>'					
						+'<input type="text"  id="project'+i+'"  autocomplete="off"   class="pull-right  add_bor_none layui-input " style="width: 60%;margin-right: 2%;border:none" readonly="readonly" value="'+resdata[i].planenddate+'"/>'					    
						+'</div>'				
						+'</div>'			

						+'<div class="buttonbox" id="saveButton" style="margin-top:10px;height: 30px">'									
						+'<div class="submit_button w94 bg_orange" id="genjin'+i+'" >跟进</div>'	
						+'</div>'				
						+'</div>'	
						+'</div>'		
					
		
					
				);
				//待办事项跟进按钮
				var genjinid = "genjin"+i;
				genjin=document.getElementById(genjinid);
				genjin.onclick=function(){
			 		var id = $(this).attr('id');
				    var num = id.substring(6); 
			 	    url = "shop_open_genjin?sno="+resdata[num].sno+'&processId=' + resdata[num].processid+'&processdId=' + resdata[num].processdid;//此处拼接内容
			        window.location.href = url;
			    }
				sum+=1;
				if(i==resdata.length-1){
					$('#sum'+title).html(sum);
				}
	}
	//待办事项
			/*var sumone = 0;	var sumtwo = 0;	var sumthree = 0;	var sumfour = 0;
			for(var i=0;i<thesum;i++){	
				if(resdata[i].jindu==undefined){
				resdata[i].jindu="";
				}	
			var thedisplay='';
			var thedisplay1='display:none';
			var thedisplay2='display:none';
			var theflag='未回复';
			var xieruid = '';
			var showname=''; var showsum=0;
			if(resdata[i].flag==10){thedisplay='display:none';thedisplay1='';theflag='未完成'; thecolor = 'blue'}	  //控制显示的按钮
			if(resdata[i].flag==500){theflag='已回复'; thecolor = 'blue'}	
			if(resdata[i].enddate==undefined){resdata[i].enddate=" "};     //避免显示undefined
			if(resdata[i].endtime==undefined){resdata[i].endtime=" "};     //避免显示undefined
			if(resdata[i].replydate==undefined){resdata[i].replydate=" "}; //避免显示undefined
			if(resdata[i].plantype==1){xieruid = 'gerenDiv';thedisplay2 = '';thedisplay1='display:none';thedisplay='display:none'; sumfour+=1; showname = '个人计划' ;showsum = sumfour;}
			else if(resdata[i].plantype==2&&resdata[i].flag == 12){xieruid = 'weihfDiv';sumtwo+=1; showname = '未回复事项';showsum = sumtwo;}
			else if(resdata[i].plantype==2&&resdata[i].flag == 500){xieruid = 'yihfDiv';sumthree+=1; showname = '已回复事项'; showsum = sumthree;}
			else if(resdata[i].plantype==2&&resdata[i].flag == 10){xieruid = 'weiDiv';sumone+=1; showname = '未完成事项'; showsum = sumone;}
	$('#'+xieruid).append('<div class="widget-header widget-header-flat widget-header-small" style="border-top:10px #e5e5e5 solid;">'   //待办事项标题 e5e5e5 
					+'<h5 class="black" style="">'+showname+showsum+'</h5>'
					+'<div class="widget-toolbar" id="shangpinmore">'
					+'<h5><font color="orange">'+theflag+'</font></h5>'
					+'</div>'
					+'</div>');					
					
	$('#'+xieruid).append('<div class="col_box">'                                               //待办事项内容
						+'<div>'							
						+'<div class="widget-box">'			
						+'<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_bgrey">'
						+'<h5 id="wentishuomingTitle"><i class="iconfont">&#xe600;</i>&nbsp;工作内容</h5><span class="red"></span>'
						+'</div>'
						+'<div class="widget-body zhediebox1">'
						+'<div class="widget-main pd_div" style="padding:0;">'
						+'<div class="clearfix jy_div" style="padding:0;">'
						+'<textarea id="content'+i+'"  rows="" cols="" class="pull-left add_bor_none add_pad_tb10p" readonly="readonly" >'+resdata[i].content+'</textarea>'
						+'</div>'
						+'</div></div></div></div>'	
						
						+'<div style="'+thedisplay1+'">'	
						+'<div class="widget-box">'			
						+'<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_bgrey ">'				
						+'<h5><i class="iconfont">&#xe609;</i>&nbsp;预计完成时间<span class="red"></span></h5>'					
						+'<input type="text"  id="enddate'+i+'"  autocomplete="off"   class="pull-right  add_bor_none layui-input " style="width: 60%;margin-right: 2%;border:none" readonly="readonly" value="'+resdata[i].enddate+' '+resdata[i].endtime+'"/>'					    
						+'</div>'				
						+'</div>'			
						+'</div>'
														
						+'<div style="'+thedisplay+'">'	
						+'<div class="widget-box">'			
						+'<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_bgrey ">'				
						+'<h5><i class="iconfont">&#xe609;</i>&nbsp;预计回复时间<span class="red"></span></h5>'					
						+'<input type="text"  id="replydate'+i+'"  autocomplete="off"   class="pull-right  add_bor_none layui-input " style="width: 60%;margin-right: 2%;border:none" readonly="readonly" value="'+resdata[i].replydate+'"/>'					    
						+'</div>'				
						+'</div>'			
						+'</div>'
								
						+'<div>'		
						+'<div class="widget-box">'			
						+'<div class="widget-header widget-header-flat widget-header-small add_pad_tb10p add_bor_bgrey">'       			
						+'<h5><i class="iconfont">&#xe603;</i>&nbsp;完成进度<span class="red"></span></h5>'	
						+'<input type="text" id="jindu'+i+'" class="pull-right add_bor_none" autocomplete="off" style="width: 70%;margin-right: 2%;border:none" readonly="readonly" value="'+resdata[i].jindu+'" />'
						+'</div>'	
						+'</div>'
						+'</div>'	
						+'<div class="buttonbox" id="saveButton" style="margin-top:10px;height: 30px">'	

						+'<div class="submit_button w94 bg_orange" id="tofinish'+i+'" style="'+thedisplay+'">回复</div>'

						//+'<div class="submit_button bg_orange" id="toedit'+i+'" style="height:28px;line-height:28px;margin-top:-28px;margin-left:220px;">编辑</div>'	
						+'<div class="submit_button w94 bg_orange" id="genjin'+i+'" style="'+thedisplay1+'">跟进</div>'			
						+'<div class="submit_button w94 bg_orange" id="jhgenjin'+i+'" style="'+thedisplay2+'">跟进</div>'					
						+'</div>'
						+'</div>'

	);
/*	//待办事项跟进按钮
	var genjinid = "genjin"+i;
	genjin=document.getElementById(genjinid);
	genjin.onclick=function(){
 		var id = $(this).attr('id');
	    var num = id.substring(6); 
 	    url = "work_plan_genjin?pno="+resdata[num].pno;//此处拼接内容
        window.location.href = url;
    }*/
/*    thecolor = 'red';  
}         //设置各项总数
		if(sumone!=0){$('#sumOne').show();} 
		if(sumtwo!=0){$('#sumTwo').show();}
		if(sumthree!=0){$('#sumThree').show();} 
		if(sumfour!=0){$('#sumFour').show();}
		$('#sumOne').html(sumone);
		$('#sumTwo').html(sumtwo);
		$('#sumThree').html(sumthree);
		$('#sumFour').html(sumfour);    */
}